<template>
  <div style="height: 100%">
  </div>
</template>

<script>
  import Format from '@/utils/format'
  import EchartsMixins from '../echarts.mixins'

  export default {
    mixins: [EchartsMixins],
    data () {
      return {
        charts: '',
        xList: [],
        yList: [],
        xyList: [],
        timerList: [],
        // 监测点名称
        monitorName: '',
      }
    },
    computed: {
      options () {
        const that = this
        const Echarts = require('echarts')
        return {
          title: {
            text: this.monitorName + '监测点累计位移变化曲线图',
            x: 'center',
            align: 'right'
          },
          grid: {
            left: '70px',
            right: '80px',
            bottom: '80px'
          },
          legend: {
            data: ['累计水平位移', '累计竖向位移'],
            x: 'right',
            y: 'top',
            orient: 'vertical',
            padding: [55, 15, 0, 0]
          },
          toolbox: {
            right: '20',
            feature: {
              dataZoom: {
                yAxisIndex: 'none'
              },
              restore: {},
              saveAsImage: {}
            }
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'line',

              label: {
                backgroundColor: '#505765'
              }
            },
            formatter: (params, ticket, callback) => {
              var contentArr = []
              contentArr.push(Format(new Date(params[0].value[0])))
              for (var i = 0; i < params.length; i++) {
                var data = params[i]
                contentArr.push(data.marker + data.seriesName + '：' + data.value[1] + 'mm')
              }
              let remark = params[0]?.data?.remark || ''
              remark && contentArr.push(`<p style='font-size:10px;' >${this.sliceStr(remark)}</p>`)
              return contentArr.join('<br/>')
            },

          },
          dataZoom: [
            {
              show: true,
              realtime: true,
              handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
              handleSize: '80%',
              handleStyle: {
                color: '#fff',
                shadowBlur: 3,
                shadowColor: 'rgba(0, 0, 0, 0.6)',
                shadowOffsetX: 2,
                shadowOffsetY: 2
              }
            },
            {
              // Y轴的滚动条
              type: 'slider',
              show: true,
              yAxisIndex: [0],
              top:'10%',
              left: '0%', // 根据实际情况调整位置
              start: 0,
              end: 100 // 根据实际情况调整显示范围
            },
            {
              // X轴的滚动条
              type: 'slider',
              show: true,
              xAxisIndex: [0],
              bottom: '0%', // 根据实际情况调整位置
              start: 0,
              end: 100 // 根据实际情况调整显示范围
            },
            {
              // 内置的Y轴缩放，可以用鼠标滚轮操作
              type: 'inside',
              yAxisIndex: [0],
            },
            {
              // 内置的X轴缩放，可以用鼠标滚轮操作
              type: 'inside',
              xAxisIndex: [0],
            }
          ],
          xAxis: {
            splitLine: {
              show: false
            },
            type: 'time',
            symbol: 'none',
            boundaryGap: false,
            axisLabel: { // 坐标轴标签样式设置
              showMaxLabel: true,
              formatter: function (value, index) { // 坐标轴文字展示样式处理
                return Echarts.format.formatTime('yyyy-MM-dd', new Date(value))
              },
            }
          },
          yAxis: {
            name: '位移',
            type: 'value',
            max: function (value) {
              if (value.max <20) {
                return 20;
              }
              return Math.ceil(value.max);//向上取整
            },
            axisLine: { // y轴
              show: true
            },
          },
          series: [
            {
              name: '累计水平位移',
              type: 'line',

              smooth: false,
              symbol: 'triangle',
              symbolSize: 4,
              data: this.xList
            },
            {
              name: '累计竖向位移',
              type: 'line',
              smooth: false,
              symbol: 'diamond',
              symbolSize: 4,
              data: this.yList
            }
            ]
        }
      }
    },
    methods: {
      updateEchart (data, monitorName,monitorInfo) {
        this.charts.clear()
        this.monitorName = monitorName
        // this.firstDataTime = monitorInfo.firstDataTime
        this.xList = data.horizontal;
        this.yList = data.vertical;
        this.timerList = data.createTime;
        this.charts.setOption(this.options)
        this.charts.resize()
      },
    },
  }
</script>
